<table width="100%"><tr><td width="20%">
<a href="../index.html">&lt; index</a><br />
<a href="index.html">&lt; 12. Field of view toolkit</a><br />
<a href="fov_init.html">&lt; 12.1 Building the map</a>
</td><td width="60%">
<p align="center">
=====================================<br />
12.2 Computing the field of view<br />
=====================================<br />
</p></td><td width="20%">
<a href="fov_get.html">&gt; 12.3 Reading fov information</a>
</td></tr></table>
<style type="text/css">
.code { color:#444444; background-color:#EEEEEE;}
pre { color:#444444; background-color:#EEEEEE;}
table.param td { border : 1px solid #000000; }
th { background-color: #44BBFF; color: #FFFFFF }
table.none td { border : 0 }
</style>
Once your map is allocated and empty cells have been defined, you can calculate the field of view with :<br />
<p class="code"><pre>
typedef enum { FOV_BASIC, 
               FOV_DIAMOND, 
               FOV_SHADOW, 
               FOV_PERMISSIVE_0,FOV_PERMISSIVE_1,FOV_PERMISSIVE_2,FOV_PERMISSIVE_3,
			   FOV_PERMISSIVE_4,FOV_PERMISSIVE_5,FOV_PERMISSIVE_6,FOV_PERMISSIVE_7,FOV_PERMISSIVE_8, 
               NB_FOV_ALGORITHMS } TCOD_fov_algorithm_t;
C++ : void TCODMap::computeFov(int playerX,int playerY, int maxRadius=0,bool light_walls = true, TCOD_fov_algorithm_t algo = FOV_BASIC)
C   : void TCOD_map_compute_fov(TCOD_map_t map, int player_x, int player_y, int max_radius, bool light_walls, TCOD_fov_algorithm_t algo)
Py  : map_compute_fov(map, player_x, player_y, max_radius=0, light_walls=True, algo=FOV_BASIC )
</pre></p>
FOV_BASIC : classic libtcod fov algorithm (ray casted from the player to all the cells on the submap perimeter)<br />
FOV_DIAMOND : based on <a href="http://www.geocities.com/temerra/los_rays.html">this algorithm</a><br />
FOV_SHADOW : based on <a href="http://roguebasin.roguelikedevelopment.org/index.php?title=FOV_using_recursive_shadowcasting">this algorithm</a><br />
FOV_PERMISSIVE_x : based on <a href="http://roguebasin.roguelikedevelopment.org/index.php?title=Precise_Permissive_Field_of_View">this algorithm</a><br />
Permissive has a variable permissiveness parameter. You can either use the constants FOV_PERMISSIVE_x, x between 0 (the less permissive) and 8 (the more permissive), or using the macro FOV_PERMISSIVE(x).
Comparison of the algorithms :<br />
Check <a href="http://roguecentral.org/libtcod/fov/fov.pdf">this</a>.
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>map</td><td>In the C version, the map handler returned by the TCOD_map_new function.</td></tr>
<tr><td>player_x,player_y</td><td>Position of the player in the map.<br />0 &lt;= player_x &lt; map width.<br />0 &lt;= player_y &lt; map height.</td></tr>
<tr><td>maxRadius</td><td>If &gt; 0, the fov is only computed up to maxRadius cells away from the player. Else, the range is unlimited.</td></tr>
<tr><td>light_walls</td><td>Wether the wall cells near ground cells in fov must be in fov too.</td></tr>
<tr><td>algo</td><td>FOV algorithm to use.</td></tr>
</table>
<br />
Example :<br />
<p class="code"><pre>
C++ : TCODMap *map = new TCODMap(50,50); // allocate the map
      map->setProperties(10,10,true,true); // set a cell as 'empty'
      map->computeFov(10,10); // calculate fov from the cell 10x10 (basic raycasting, unlimited range, walls lighting on)
C   : TCOD_map_t map = TCOD_map_new(50,50);
      TCOD_map_set_properties(map,10,10,true,true);
      TCOD_map_compute_fov(map,10,10,0,true,FOV_SHADOW); // using shadow casting
Py  : map = libtcod.map_new(50,50)
      libtcod.map_set_properties(map,10,10,True,True)
      libtcod.map_compute_fov(map,10,10,0,True,libtcod.FOV_PERMISSIVE(2)) 
</pre></p>
